import pandas as pd
import os


def load_events(data_dir="data"):
    print("📥 正在加载事件数据...")
    events_path = os.path.join(data_dir, "events.csv")
    df = pd.read_csv(events_path)

    df['timestamp'] = pd.to_datetime(df['timestamp'], unit='ms')

    return df



def load_category_tree(data_dir="data"):
    path = os.path.join(data_dir, "category_tree.csv")
    try:
        return pd.read_csv(path)
    except FileNotFoundError:
        print(f"❌ File not found: {path}")
        return pd.DataFrame()


def load_item_properties(data_dir="data"):
    path1 = os.path.join(data_dir, "item_properties_part1.csv")
    path2 = os.path.join(data_dir, "item_properties_part2.csv")

    try:
        df1 = pd.read_csv(path1)
        df2 = pd.read_csv(path2)
        df = pd.concat([df1, df2], ignore_index=True)
        df['timestamp'] = pd.to_datetime(df['timestamp'], unit='s')
        return df
    except FileNotFoundError as e:
        print(f"❌ File not found: {e.filename}")
        return pd.DataFrame()
